#include <gtk/gtk.h>
#include <glade/glade.h>
#include "list.h"

char *name1[]={"Colben","Shelly","Saferin","Ada","Obo","Kathy",NULL};    //之前
char *name2[]={"Colben","Shelly","Bather","Ada","Obo","Kathy","Jathy","Rassol","Colben","Shelly","Bather","Rassol","Colben","Shelly","Bather","Ada","Obo","Kathy",NULL};    //之后

void list_select_back(gpointer data)    //双击选中回调
{
	LIST *list=(LIST *)data;
	gtk_label_set_text(GTK_LABEL(list->out),cgtk_list_get_select_text(list));
	printf("\n>>>>>>----------%d----------<<<<<<\n",cgtk_list_get_select_num(list));
	printf("\n>>>>>>----------%s----------<<<<<<\n",cgtk_list_get_select_text(list));
}

void button_refresh_list(GtkWidget *widget,gpointer data)    //按钮单击回调
{
	LIST *list=(LIST *)data;
	cgtk_list_refresh(list,name2);
}

int main(int argc,char *argv[])
{
	gtk_init(&argc,&argv);
	GladeXML *gxml=glade_xml_new("test.glade",NULL,NULL);
	GtkWidget *main_window=glade_xml_get_widget(gxml,"window1");
	g_signal_connect(main_window,"destroy",G_CALLBACK(gtk_main_quit),NULL);

	GtkWidget *fixed=glade_xml_get_widget(gxml,"fixed1");
	GtkWidget *label=glade_xml_get_widget(gxml,"label1");

	LIST *list=cgtk_list_new(name1,240,40,8,label);    //创建列表，指针即可，无需分配空间
	if(NULL == list)
	{
		printf("\n>>>>>> !!! Memory not enough !!! <<<<<<\n");
		return -1;
	}
	gtk_fixed_put(GTK_FIXED(fixed),list->event_box,500,80);    //把列表添加到主窗口的固定布局中

	GtkWidget *button=glade_xml_get_widget(gxml,"button1");
	g_signal_connect(button,"clicked",G_CALLBACK(button_refresh_list),list);    //按钮信号注册

	gtk_widget_show_all(main_window);
	gtk_main();
	return 0;
}
